import torch
import numpy as np
from torch import nn
from torch.autograd import Variable
from torch import optim


class CNN(nn.Module):
    def __init__(self):  # (11,11) 11*11 
        super(CNN, self).__init__()

        self.layer1 = nn.Sequential(
            nn.Conv2d(1, 16, (3, 3)),  # 16,9,9
            nn.BatchNorm2d(16),
            nn.ReLU(inplace=True)
        )

        self.layer2 = nn.Sequential(
            nn.Conv2d(16, 32, (3, 3)),  # 32,7,7
            nn.BatchNorm2d(32),
            nn.ReLU(inplace=True),
        )

        self.layer3 = nn.Sequential(
            nn.Conv2d(32, 64, (3, 3)),  # 64,5,5
            nn.BatchNorm2d(64),
            nn.ReLU(inplace=True),
        )

        self.layer4 = nn.Sequential(
            nn.Conv2d(64, 128, (3, 3)),  # 128,3,3
            nn.BatchNorm2d(128),
            nn.ReLU(inplace=True),
        )

        self.fc = nn.Sequential(
            nn.Linear(128 * 3 * 3, 384),
            nn.ReLU(inplace=True),
            nn.Linear(384, 213)
        )

    def forward(self, x):
        x = self.layer1(x)
        x = self.layer2(x)
        x = self.layer3(x)
        x = self.layer4(x)
        # print(x.shape)
        x = x.view(x.size(0), -1)
        x = self.fc(x)
        return x

